﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>用户离职管理</title>
    <link rel="stylesheet" href="/Content/Scripts/bootstrap-3.3.6/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/Content/Scripts/bootstrap-3.3.6/css/bootstrap-datetimepicker.min.css" />
</head>
    <body>
        <form id="uiForm" class="form-horizontal" role="form">
            <input type="hidden" id="Id" name="Id" />
            <fieldset class="has-success" disabled>
                <legend>用户信息</legend>
                <div class="form-group">
                    <label class="col-sm-2 control-label" for="UserName">用户登录名</label>
                    <div class="col-sm-8">
                        <input type="text" id="UserName" name="UserName" class="form-control" placeholder="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="username" class="col-sm-2 control-label">姓名</label>
                    <div class="col-sm-8">
                        <input type="text" id="RealName" name="RealName" class="form-control" placeholder="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="lastname" class="col-sm-2 control-label">岗位</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="Duty" name="Duty" placeholder="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="lastname" class="col-sm-2 control-label">默认角色</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="RoleName" name="RoleName" placeholder="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="lastname" class="col-sm-2 control-label">公司/单位</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="CompanyName" name="CompanyName" placeholder="">
                    </div>
                </div>
                <div class="form-group">
                    <label for="lastname" class="col-sm-2 control-label">所在部门</label>
                    <div class="col-sm-8">
                        <input type="text" class="form-control" id="DepartmentName" name="DepartmentName" value="">
                    </div>
                </div>
            </fieldset>
            <fieldset>
                <legend>离职情况</legend>
                <div class="form-group row">
                    <label class="col-sm-2 control-label" for="DismissionDate">离职日期</label>
                    <div class="col-sm-3">
                        <div class="input-append date" id="datetimepicker" data-date="2016-05-01" data-date-format="yyyy-mm-dd">
                            <input id="DimissionDate" name="DimissionDate" size="16" type="text" />
                            <span class="add-on"><i class="icon-th"></i></span>
                        </div>
                    </div>
                    <div class="col-sm-3">
                        <input type="checkbox" id="IsDimission" name="IsDimission"> 是否离职
                    </div>
                </div>
                <div class="form-group">
                    <label for="lastname" class="col-sm-2 control-label">离职原因</label>
                    <div class="col-sm-8">
                        <textarea id="DimissionCause" name="DimissionCause" class="form-control" rows="2"></textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label for="lastname" class="col-sm-2 control-label">离职去向</label>
                    <div class="col-sm-8">
                        <textarea id="DimissionWhither" name="DimissionWhither" class="form-control" rows="2"></textarea>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-1 col-sm-8">
                        <button id="btnSubmit" class="btn btn-primary">
                            <span class="glyphicon glyphicon-ok"></span> 提 交
                        </button>
                        <button id="btnClose" class="btn btn-default">
                            <span class="glyphicon glyphicon-remove"></span> 关 闭
                        </button>
                    </div>
                </div>
            </fieldset>
        </form>
        <script type="text/javascript" src="/Content/Scripts/jquery-1.12.1.min.js"></script>
        <script type="text/javascript" src="/Content/Scripts/bootstrap-3.3.6/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="/Content/Scripts/bootstrap-3.3.6/bootstrap-datetimepicker.min.js"></script>
        <script type="text/javascript" src="/Content/Scripts/bootstrap-3.3.6/bootstrap-datetimepicker.zh-CN.js"></script>
        <script type="text/javascript" src="/Content/Scripts/easyui/jquery.validate.js"></script>
        <script type="text/javascript" src="/Content/Scripts/hpwf-core.js"></script>
        <script type="text/javascript" src="/Content/Scripts/jQuery.Ajax.js"></script>
        <script type="text/javascript" src="/Content/Scripts/jQuery.cookie.js"></script>
        <script type="text/javascript" src="/Content/Scripts/csrf.js"></script>
        <script type="text/javascript">
            $(function () {
                $('#btnSubmit').attr('onclick', 'return SubmitForm();');
                $('#btnClose').attr('onclick', 'CloseWindow();');
                $('#DimissionDate').datetimepicker({
                    format: 'yyyy-mm-dd',
                    weekStart: 1,
                    todayBtn: 0,
                    autoclose: 1,
                    startView: 2,
                    minView: 3,
                    language: 'zh-CN',
                    forceParse: 1,
                    showMeridian: 1
                });
                handleSubmit();
            });

            var handleSubmit = function() {
                $('.form-horizontal').validate({
                    errorElement: 'span',
                    errorClass: 'help-block',
                    focusInvalid: false,
                    rules: {
                        DimissionDate: {
                            required: true
                        },
                        IsDimission: {
                            required: true
                        },
                        DimissionCause: {
                            required: true
                        }
                    },
                    messages: {
                        DimissionDate: {
                            required: "DimissionDate is required."
                        },
                        IsDimission: {
                            required: "IsDimission is required."
                        },
                        DimissionCause: {
                            required: "DimissionCause is required."
                        }
                    },

                    highlight: function(element) {
                        $(element).closest('.form-group').addClass('has-error');
                    },

                    success: function(label) {
                        label.closest('.form-group').removeClass('has-error');
                        label.remove();
                    },

                    errorPlacement: function(error, element) {
                        element.parent('div').append(error);
                    }
                });
            };

            var BindPage = function (id) {
                $.ajaxjson("/Admin/FrameworkModules/UserAdmin/GetEntity/", 'key=' + id, function (data) {
                    if (data) {
                        if (data.IsDimission) { //已离职就不要再去修改了
                            $("#btnSubmit").attr("disabled", true);
                        }
                        SetWebControls(data, false);
                    }
                });
                //$('#DimissionDate').focus();
            };
        
            function SubmitForm() {
                if (!$('.form-horizontal').validate().form()) {
                    return false;
                }
                if (confirm('确定离职?')) {
                    var postData = pageMethod.serializeJson($('#uiForm'));
                    $.ajaxjson("/Admin/FrameworkModules/UserAdmin/SetUserDimission/", postData, function (d) {
                        if (d.Success) {
                            alert(d.Message);
                            CloseWindow();
                            return true;
                        } else {
                            alert(d.Message);
                            //BindPage($('#Id').val());
                            return false;
                        }
                    });
                }else{
                    return false;
                }
            }
			
            var CloseWindow = function () {
                var currTopTab = top.$('#tabs');
                var currtabTitle = currTopTab.tabs('getSelected').panel('options').title;
                currTopTab.tabs('close', currtabTitle);
            };
        </script>
    </body>

</html>